package org.tulkas.http.headers;

import java.util.Date;

import org.apache.http.impl.cookie.DateUtils;
import org.tulkas.http.headers.CacheControls.RequestCacheControls;

/**
 * Standard Http request headers.
 * Default values for every header element is null, if null is set the element is not include in the http message.
 * For header reference, see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">W3 Http protocol section 14</a>
 * @author <a href="mailto:tulkas.web@gmail.com">Tulkas</a>
 *
 */
public class RequestHeaders extends HttpHeaders {
	//static values for typical headers
	public static final MediaTypes MEDIA_TYPEs = MediaTypes.TYPICAL;
	public static final ContentEncodings CONTENT_ENCODINGs = ContentEncodings.TYPICAL;
	public static final UserAgents USER_AGENTs = UserAgents.TYPICAL;
	public static final RequestCacheControls CACHE_CONTROLs = CacheControls.REQUEST;

	/**
	 * Accept header, e.g. "text/html, image/*"
	 */
	public String getAccept() {
		return getHeader("Accept");
	}

	public void setAccept(String accept) {
		updateHeader("Accept", accept);
	}

	/**
	 * Accept-Charset header, e.g. "iso8859-5"
	 */
	public String getAcceptCharset() {
		return getHeader("Accept-Charset");
	}

	public void setAcceptCharset(String acceptCharset) {
		updateHeader("Accept-Charset", acceptCharset);
	}

	/**
	 * Accept-Encoding header, e.g. "gzip, compress"
	 */
	public String getAcceptEncoding() {
		return getHeader("Accept-Encoding");
	}

	public void setAcceptEncoding(String acceptEncoding) {
		updateHeader("Accept-Encoding", acceptEncoding);
	}

	/**
	 * Accept-Language header, e.g. "en, fr"
	 */
	public String getAcceptLanguage() {
		return getHeader("Accept-Language");
	}

	public void setAcceptLanguage(String acceptLanguage) {
		updateHeader("Accept-Language", acceptLanguage);
	}

	/**
	 * Authorization header
	 */
	public String getAuthorization() {
		return getHeader("Authorization");
	}

	public void setAuthorization(String authorization) {
		updateHeader("Authorization", authorization);
	}

	/**
	 * Expect header, e.g. "100-continue"
	 */
	public String getExpect() {
		return getHeader("Expect");
	}

	public void setExpect(String expect) {
		updateHeader("Expect", expect);
	}

	/**
	 * From header, e.g. "user@kevinth.com"
	 */
	public String getFrom() {
		return getHeader("From");
	}

	public void setFrom(String from) {
		updateHeader("From", from);
	}

	/**
	 * Host header, e.g. "www.kevinth.com"
	 */
	public String getHost() {
		return getHeader("Host");
	}

	public void setHost(String host) {
		updateHeader("Host", host);
	}

	/**
	 * If-Match header, e.g. "entity_tag001"
	 */
	public String getIfMatch() {
		return getHeader("If-Match");
	}

	public void setIfMatch(String ifMatch) {
		updateHeader("If-Match", ifMatch);
	}

	/**
	 * If-Modified-Since header, will be format to http date, e.g. "Tue, 11 Jul 2000 18:23:51 GMT"
	 */
	public Date getIfModifiedSince() {
		String str = getHeader("If-Modified-Since");
		return parseDate(str);
	}

	public void setIfModifiedSince(Date ifModifiedSince) {
		updateHeader("If-Modified-Since", DateUtils.formatDate(ifModifiedSince));
	}

	/**
	 * If-None-Match header, e.g. "entity_tag001"
	 */
	public String getIfNoneMatch() {
		return getHeader("If-None-Match");
	}

	public void setIfNoneMatch(String ifNoneMatch) {
		updateHeader("If-None-Match", ifNoneMatch);
	}

	/**
	 * If-Range header, e.g. "entity_tag001" or "Tue, 11 Jul 2000 18:23:51 GMT"
	 */
	public String getIfRange() {
		return getHeader("If-Range");
	}

	public void setIfRange(String ifRange) {
		updateHeader("If-Range", ifRange);
	}

	/**
	 * If-Unmodified-Since header, will be format to http date, e.g. "Tue, 11 Jul 2000 18:23:51 GMT"
	 */
	public Date getIfUnmodifiedSince() {
		String str = getHeader("If-Unmodified-Since");
		return parseDate(str);
	}

	public void setIfUnmodifiedSince(Date ifUnmodifiedSince) {
		updateHeader("If-Unmodified-Since", DateUtils
				.formatDate(ifUnmodifiedSince));
	}

	/**
	 * Max-Forwards header, e.g. "3"
	 */
	public Integer getMaxForwards() {
		String str = getHeader("Max-Forwards");
		if (str != null)
			return Integer.parseInt(str);
		else
			return null;
	}

	public void setMaxForwards(Integer maxForwards) {
		updateHeader("Max-Forwards", maxForwards.toString());
	}

	/**
	 * Proxy-Authorization header
	 */
	public String getProxyAuthorization() {
		return getHeader("Proxy-Authorization");
	}

	public void setProxyAuthorization(String proxyAuthorization) {
		updateHeader("Proxy-Authorization", proxyAuthorization);
	}

	/**
	 * Range header, e.g. "bytes=100-599"
	 */
	public String getRange() {
		return getHeader("Range");
	}

	public void setRange(String range) {
		updateHeader("Range", range);
	}

	/**
	 * Referer header, e.g. "http://www.kevinth.com/resources.html"
	 */
	public String getReferer() {
		return getHeader("Referer");
	}

	public void setReferer(String referer) {
		updateHeader("Referer", referer);
	}

	/**
	 * TE header, e.g. "trailers"
	 */
	public String getTE() {
		return getHeader("TE");
	}

	public void setTE(String tE) {
		updateHeader("TE", tE);
	}

	/**
	 * User-Agent header, e.g. "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"
	 */
	public String getUserAgent() {
		return getHeader("User-Agent");
	}

	public void setUserAgent(String userAgent) {
		updateHeader("User-Agent", userAgent);
	}

}
